package com.bbt.dormassistant.service.impl;

import com.bbt.dormassistant.dao.ActivityRoomMapper;
import com.bbt.dormassistant.entity.ActivityRoom;
import com.bbt.dormassistant.service.ActivityRoomService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ActivityRoomServiceImpl implements ActivityRoomService {


    @Resource
    private ActivityRoomMapper activityRoomMapper;


    /**
     *
     * @return List<ActivityRoom>
     */
    @Override
    public List<ActivityRoom> queryActivityRoom() {
        return activityRoomMapper.selectAll();
    }


    /**
     *
     * @param RoomId 房间ID
     * @return ActivityRoom
     */
    @Override
    public ActivityRoom queryActivityRoomById(int RoomId) {
        return activityRoomMapper.selectByPrimaryKey(RoomId);
    }


    /**
     *
     * @param userId 用户ID
     * @param building 建筑
     * @param room 房间号
     * @return Boolean
     */
    @Override
    public Boolean addActivityRoom(String userId, String building, Integer room) {
        try {
            ActivityRoom activityRoom = new ActivityRoom();
            activityRoom.setUserId(userId);
            activityRoom.setBuilding(building);
            activityRoom.setRoom(room);
            return activityRoomMapper.insert(activityRoom) == 1;
        }catch (Exception e ){
            e.printStackTrace();
            return false;
        }
    }

    /**
     *
     * @param activityRoomId 需要被修改的活动室ID
     * @param userId 用户ID
     * @param building 楼栋
     * @param room 房间号
     * @return Boolean
     */
    @Override
    public Boolean modifyActivityRoom(Integer activityRoomId, String userId, String building, Integer room) {
        ActivityRoom activityRoom = new ActivityRoom();
        activityRoom.setUserId(userId);
        activityRoom.setBuilding(building);
        activityRoom.setRoom(room);
        return activityRoomMapper.updateByPrimaryKey(activityRoom) == 1;
    }


    /**
     *
     * @param activityId 需要删除的活动室ID
     * @return Boolean
     */
    @Override
    public Boolean deleteActivityRoom(Integer activityId) {
        try {
            return activityRoomMapper.deleteByPrimaryKey(activityId) == 1;
        } catch (Exception e) {
            return false;
        }
    }


}
